#!/bin/sh

##
##  nlscopy
##
##  $Id: nlscopy,v 1.3 2003/03/13 05:13:47 bboy Exp $
##
##  If translations exist for the user's language, install them.
##

if test -z "$1"
then
	echo
	echo "USAGE: $0 top_srcdir"
	echo "This script installs translated documentation if available."
	echo
	exit
fi

TOPDIR=$1
DOCDIR=$TOPDIR/doc
NLSDIR=$DOCDIR/nls
LANGFILE=$DOCDIR/LANG


##
##  Don't do this again
##
if test -f $LANGFILE
then
	exit
fi


##
##  Does a directory exist with translations for this user's language?
##
if ! test -z "$LANG"
then
	if test -d $NLSDIR/$LANG
	then
		LANGDIR=$NLSDIR/$LANG
		LANGUAGE=$LANG
	else
		TLANG=`echo $LANG | $TOPDIR/missing --run sed -e 's/_..//'`
		if test -d $NLSDIR/$TLANG
		then
			LANGDIR=$NLSDIR/$TLANG
			LANGUAGE=$TLANG
		fi
	fi
fi


##
##  If we found a language dir, copy files
##
if test -z "$LANGDIR"
then
	##
	##  Output langfile for English users
	##
	echo > $LANGFILE
	echo "Standard (non-translated) documentation being used." >> $LANGFILE
	echo >> $LANGFILE
	echo "This is the default.  This file is here as a placeholder, so that \"make\"" >> $LANGFILE
	echo "won't try multiple times to install translated documentation." >> $LANGFILE
	echo >> $LANGFILE
	exit
fi

echo
echo "***"
echo "***  Translated documentation found for \"$LANGUAGE\""
echo "***"


##
##  Output langfile for non-English users (in English, huh?)
##
echo > $LANGFILE
echo "Documentation using language \"$LANGUAGE\"." >> $LANGFILE
echo >> $LANGFILE
echo "For information on installing the supplied, always up-to-date, original" >> $LANGFILE
echo "documentation, please read the \"NATIVE LANGUAGE SUPPORT\" section of the" >> $LANGFILE
echo "README file reproduced below:" >> $LANGFILE
echo >> $LANGFILE
cat $DOCDIR/README >> $LANGFILE
echo >> $LANGFILE


##
##  Copy translated manual pages
##
for f in $LANGDIR/man/*.[0-9]
do
	if test -f $f
	then
		FILE=`basename $f`

		if ! test -f $DOCDIR/man/$FILE.en
		then
			mv -f $DOCDIR/man/$FILE $DOCDIR/man/$FILE.en
		fi
		cp -f $f $DOCDIR/man/$FILE
		echo "***  $FILE -> $DOCDIR/man/$FILE"
	fi
done


##
##  Copy translated texinfo files
##
for f in $LANGDIR/texinfo/*.texi
do
	if test -f $f
	then
		FILE=`basename $f`

		if ! test -f $DOCDIR/texinfo/$FILE.en
		then
			mv -f $DOCDIR/texinfo/$FILE $DOCDIR/texinfo/$FILE.en
		fi
		cp -f $f $DOCDIR/texinfo/$FILE
		echo "***  $FILE -> $DOCDIR/texinfo/$FILE"
	fi
done

echo "***"
echo

## vi:set ts=3:
